﻿using UnityEngine;
using System.Collections;
using System;
using DICE_GS;

public class EnemyChoiceEnemy : MonoBehaviour {

	public int sid;

	void OnPress (bool isDown)
	{
		CameraControl cc = Camera.main.gameObject.GetComponent<CameraControl>();
		if(isDown)
		{
			cc.PressedUIButton(true);
			UIManager.Instance.CallDelayedPressUp();
			if(SkillManager.Instance.bWaitSelectTarget)
			{
				SkillManager.Instance.CastSkillToTarget( sid );
			}
		}
	}

	public void Init(int _sid, int nOrder)
	{
		sid = _sid;
		BoardPerson person = StageManagerWrapper.GetBoardPerson(sid);
		int nRank = MainHUDUI.Instance.CheckMyRank(nOrder-1);
		string nickname = person.nickName;
		string sprName = String.Format("IngameUi_cha{0:00}",person.charID);
		transform.FindChild("name").gameObject.GetComponent<UILabel>().text = nickname;
		string rankStr = CStringTableManager.Instance.GetItemById(2368);
		transform.FindChild("Title").gameObject.GetComponent<UILabel>().text = rankStr.Replace("{0}",nRank.ToString());
		//transform.FindChild("Title").gameObject.GetComponent<UILabel>().text = nRank.ToString();
		transform.FindChild("char").gameObject.GetComponent<UISprite>().spriteName = sprName;

		//buff icon
		GameObject skill1Go = transform.FindChild("Skill1").gameObject;
		GameObject skill2Go = transform.FindChild("Skill2").gameObject;
		skill1Go.SetActive(false);
		skill2Go.SetActive(false);
		var list = HudManager.Instance.sidBufIconsDic[sid];
		foreach( BuffIcon icon in list)
		{
			if(icon.isActive)
			{
				if(icon.index==0)
				{
					skill1Go.SetActive(true);
					skill1Go.transform.FindChild("SkillIcon").gameObject.GetComponent<UISprite>().spriteName = icon.sprite.spriteName;
				}
				else if(icon.index==1) {
					skill2Go.SetActive(true);
					skill2Go.transform.FindChild("SkillIcon").gameObject.GetComponent<UISprite>().spriteName = icon.sprite.spriteName;
				}
			}
		}
	}
}
